//
//  HotViewcontroller.m
//  YSBEmployer
//
//  Created by developer on 2021/12/05.
//  Copyright © 2021 ysb. All rights reserved.
//

#import "YSBHomeWorkTypeView.h"

#import "YSBSwitchWorkTitlesView.h"

#import "YSBOrderListHomeMainViewController.h"

#import "HttpClient.h"

#import "YSBPermanentWorkerPayResultController.h"

#import "YSBEmployerHomeController.h"


@implementation YSBEmployerHomeController


#pragma mark - 修改首页滑动存在的问题
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(nonnull NSArray<UIViewController *> *)previousViewControllers transitionCompleted:(BOOL)completed {
    
    if (completed) {
        UIViewController *viewController = [self.pageVC.viewControllers firstObject];
        NSUInteger index = [self.VCArray indexOfObject:viewController];
        self.selectedIndex = index;
        [self resetMenuSelectedIndex:index];
    }
}

#pragma mark - 修改首页菜单显示菜单宽度由文字长度决定
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    CGFloat textWidth = 0;
    
    if (self.menuModelArray.count > 0) {
        JXCategorySubtitleCellModel *model = self.menuModelArray[indexPath.item];
        textWidth = model.titleFont.pointSize * (model.title.length) + 4;
        
        CGFloat subtitleWidth = model.subtitleFont.pointSize * (model.subtitle.length) + 16;
        textWidth = textWidth > subtitleWidth ? textWidth : subtitleWidth;
        
    }
    
    NSInteger count = self.menuModelArray.count == 0 ? 1 : self.menuModelArray.count;
    CGFloat dWidth = ([[UIScreen mainScreen] bounds].size.width - 20 - 10 * (count - 1)) / count;
    
    CGFloat tWidth = textWidth < dWidth ? dWidth : textWidth;
    
    return CGSizeMake(tWidth, 50);
 
}


@end


@implementation YSBPermanentWorkerPayResultController

- (void)enterButton:(UIButton *)btn {
    [self.navigationController popViewControllerAnimated:YES];
}

@end


@implementation HttpClient

#pragma mark - 修改升级功能,去除请求苹果官网
- (void)updateMethodWithStrive:(BOOL)needStrive andUpdateContent:(NSArray *)updateContentArray andUpdateModel:(UpdateModel *)model {
    
    //获取服务器上应用的最新版本号
    NSString *updateVersion = [YSBCommonTool isBlankString:model.version_no] ? @"" : model.version_no;
    
    NSDictionary *info= [[NSBundle mainBundle] infoDictionary];
    NSString *bundleVersion = [YSBCommonTool isBlankString:info[@"CFBundleShortVersionString"]] ? @"" : info[@"CFBundleShortVersionString"];
    
    NSString *messageStr = [NSString stringWithFormat:@"发现新版本(%@),是否更新?", updateVersion];
    if (updateContentArray.count > 0) {
        NSString *updateStr = @"";
        if (updateContentArray.count > 1) {
            updateStr = [updateContentArray componentsJoinedByString:@" \n"];
        }else{
            updateStr = updateContentArray[0];
        }
        messageStr = updateStr;
    }
    
    if ([updateVersion isEqualToString:bundleVersion]) {
        //            GSToastInCenter(@"当前版本为最新版本无需更新！");
    }
    else {
        if (self.updateAlert == nil) {
            self.updateAlert = [SELUpdateAlert showUpdateAlertWithVersion:updateVersion Description:messageStr isForcingUpdate:needStrive];
            self.updateAlert.hidden = YES;
            //添加弹框界面
            if (self.updateAlert) {
                self.updateAlert.tag = 1;
                [[YSBMSAlertManager shareManager] addAlert:self.updateAlert];
            }
        }
    }
    
}


@end


@implementation YSBOrderListHomeMainViewController

#pragma mark - 修改订单列表兼容问题
- (void)resetTitleView {

    CGFloat mWidth = [[UIScreen mainScreen] bounds].size.width - 110;
    self.switchWorkTypeView.frame = CGRectMake(0, 0, mWidth, 44);
    
    self.navigationItem.titleView = self.switchWorkTypeView;
    
    NSString *version = [UIDevice currentDevice].systemVersion;
    if (version.doubleValue >= 11.0) {//iOS11及以上系统才能使用masonry布局UINaviationBar,否则会崩溃
        YSBSwitchWorkTitleCTypeView *switchWorkTypeView = [[YSBSwitchWorkTitleCTypeView alloc] init];
        switchWorkTypeView = self.switchWorkTypeView;
        [switchWorkTypeView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.navigationItem.titleView).offset(0);
            make.bottom.mas_equalTo(self.navigationItem.titleView).offset(0);
            make.height.mas_equalTo(@(44));
            make.width.mas_equalTo(@(280));
        }];
    }
    
}

@end


#pragma mark - 修改未登录,点击首页"我要招工"按钮未弹出登录界面的问题
@implementation YSBHomeWorkTypeView

- (void)nextAction:(UIButton *)btn {
    
    if (![YSBUserDefaultsTool boolForKey:@"kIsLoginSuccess"]) {
        [(YSBViewController *)[YSBCommonTool getCurrentVC] goToLoginVC];
        return;
    }
    
    if (_delegate && [_delegate respondsToSelector:@selector(nextWorkAction)]) {
        [_delegate nextWorkAction];
    }
}

@end


#pragma mark - 修改首页我要招工里面的小标题
@implementation YSBSwitchWorkTitlesView

- (UILabel *)leftSubTitleLabel{
    if (!_leftSubTitleLabel) {
        _leftSubTitleLabel = [[UILabel alloc] init];
        _leftSubTitleLabel.textAlignment = 0;
        _leftSubTitleLabel.font = [UIFont boldSystemFontOfSize:9];
        _leftSubTitleLabel.textColor = [UIColor grayColor];
        _leftSubTitleLabel.adjustsFontSizeToFitWidth = YES;
        _leftSubTitleLabel.text = @"线上雇主结";
    }
    return _leftSubTitleLabel;
}


- (UILabel *)rightSubTitleLabel{
    if (!_rightSubTitleLabel) {
        _rightSubTitleLabel = [[UILabel alloc] init];
        _rightSubTitleLabel.textAlignment = 0;
        _rightSubTitleLabel.font = [UIFont boldSystemFontOfSize:9];
        _rightSubTitleLabel.textColor = [UIColor grayColor];
        _rightSubTitleLabel.adjustsFontSizeToFitWidth = YES;
        _rightSubTitleLabel.text = @"线下自由结算";
    }
    return _rightSubTitleLabel;
}



@end
